<template>
	<view class="container">
			<view class="home_head">
				<view class="home_head_left">
					<navigator class="float-btn score" url="/pages/myScore/index">
						<image class="icon" mode="widthFix" src="@/static/money.png"></image>
						<text class="text">{{scoreAlias}}</text>
						<view class="total" v-if="userInfo.score">{{userInfo.score | bigNumberDisplay}}</view>
					</navigator>
				</view>
				<view class="home_head_right">
					<!-- <navigator url="/pages/myBox/index" class=" my-box-float-btn">
						<image src="@/static/myBox.png" mode="widthFix" class="icon"></image>
					</navigator>
					
					<navigator url="/pages/rule/index?type=fudai" class=" rule-float-btn">
						<image src="@/static/rule.png" mode="widthFix" class="icon"></image>
					</navigator> -->
				</view>
			</view>
		<view class="sper-box">
			<PageRender :refreshCounter="refreshCounter" :getNextPageCounter="getNextPageCounter" :page="page"
				theme="default"></PageRender>
		</view>
			<view class="class_type">
				<view class="class_type_item" v-for="(item, index) in classTypeArr" @tap="classTypeClick(item.uuid,index)">
						<view class="type-icon-box">
							<image class="type-icon" mode="widthFix" :src="'/static/classType/'+(index+1)+'.png'"></image>
						</view>
						<view class="text" :style="{ color:selected==index ? '#ffaa00' : '#000'}">{{item.title}}</view>
				</view>
			</view>
<PageRender :refreshCounter="refreshCounter" :getNextPageCounter="getNextPageCounter" :page="list"
			theme="default"></PageRender>
		<!-- <FloatBtn url="/pages/cart/index" :isAnimated="false" src="https://bus-cdn.hquesoft.com/box/shop-float-btn.png"></FloatBtn> -->
	</view>
</template>

<script>
	import {
		mapGetters
	} from "vuex"
	
	export default {
		components: {},
		data() {
			return {
				scrollTop: 0,
				refreshCounter: 0,
				getNextPageCounter: 0,
				uuid: null,
				info:{},
				classTypeArr:[
					{title:"限时活动",uuid:'xshd'},
					{title:"每日推荐",uuid:'mrtj'},
					{title:"3C数码",uuid:'3csm'},
					{title:"生活家电",uuid:'shjd'},
					{title:"潮玩手办",uuid:'cwsb'},
					{title:"电脑办公",uuid:'dnbg'},
					{title:"女神专属",uuid:'nszs'},
					{title:"食品饮料",uuid:'spyl'},
					{title:"户外运动",uuid:'hwyd'},
					{title:"其它",uuid:'others'},
				],
				selected:0
			}
		},
		computed: {
			...mapGetters(["userInfo"]),
			page() {
				let tmp={
					"style": [

					],
					"modules": [],
					"title": "\u65b0\u7eaa\u5143",
					"nav_color": "#FFCC00",
					"is_float_btn": 1
				};
				tmp.modules=this.$store.getters.setting.shop_home.modules.filter((e)=>e.type=="swiper")
				console.log(tmp)
				return  tmp;
			},
			list () {
				console.log(this.info.content,'this.info.content',)
				return this.info.content || {}
			}
		
		},
		
		watch: {},
		onLoad() {
			console.log(this.userInfo,'userInfo')
			this.$visitor.record('box_index');
			this.$http('/fudai/home/config').then(res => {
				this.uuid = this.GetRequest(res.data.setting.ui?.more_link?.path)?.uuid;
				this.initData();
			})
		},
		onPullDownRefresh() {
			this.$showPullRefresh().then(res => {
				this.refreshCounter++
			})
		},
		onShow() {
			
		},
		methods: {
			st_loadData(){
				let st = true;
				if(st == 1){
					console.info(1)
				}
			},
			st_list(){
				let status = true;
				if(status){
					status = false;
					console.info(222)
				}
			},
			st_pay(){
				let s = 1;
				if(s == 1){
			
				}else if(s == 2){
				
				}
			},
			classTypeClick(type,index){
				this.selected = index;
				uni.showLoading({
					title: '加载中'
				});
				// if(type==="xshd"){
				// 	//限时活动跳转
				// 	console.log(this.$store.getters.setting.activity_home,'this.$store.getters.setting.activity_home')
				// 	let _data=this.$store.getters.setting.activity_home.modules.filter((e)=>{
				// 		return e.activity_type==="lottery"&&e.type==="activities"
				// 	})
				// 	console.log(_data);
				// 	if(_data.length&&_data.length>0){
				// 		this.$http("/lotteries", 'GET', {
				// 			per_page: 1,
				// 			per_page: 1,
				// 			ids: _data[0].list_content==="all"?null:_data[0].list,
							
				// 		}).then(res => {
				// 			uni.hideLoading()
								 
				// 			 console.log(res,'res')
				// 			 if(res.code===0&&res.data&&res.data.list&&res.data.list.length>0){
				// 				 uni.navigateTo({
				// 				 	url:`/pages/lottery/detail?uuid=${res.data.list[0].uuid}`  
				// 				 })
				// 			 }else{
				// 				 uni.showToast({
				// 					 icon:'none',
				// 				 	title:"暂无活动，敬请期待"
				// 				 })
				// 			 }
				// 		})
						 
				// 	}else{
				// 		uni.showToast({
				// 			icon:'none',
				// 			title:"暂无活动，敬请期待"
				// 		})
				// 	}
					 
				// 	return
				// }
				
				this.info ={};
				this.$http(`/pages/${this.uuid}`,'GET',{
					type
				}).then(res => {
						uni.hideLoading()
					console.log(res,'res')
					if(res.code===0){
					this.info = res.data.info
					}else{
						uni.showToast({
							title:res.message
						})
					}
					
				 
				});
				
				
			},
			
			GetRequest(url) {
				//获取url中"?"符后的字串  
				var theRequest = new Object();
				if (url.indexOf("?") != -1) {
					url = "?" + url.split("?")[1]; //模拟获取参数后面的
					var str = url.substr(1);
					let strs = str.split("&");
					for (var i = 0; i < strs.length; i++) {
						theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);

					}
				}
				return theRequest;
			},
			initData(item) {
				uni.showLoading({
					title: '加载中'
				})
				if(item){
					this.search = item;
				}else{
					this.search='';
				}
				console.log(this.search);
				this.$http(`/pages/${this.uuid}`).then(res => {
					this.info = res.data.info
					console.log("this.info: ",this.info);
					uni.hideLoading()
				});
				 
			},
		},
		onReachBottom() {
			this.getNextPageCounter++
			// console.log('reach bottom')
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop
		}
	}
</script>

<style lang="scss" scoped>
	.container{
		background: #F2F2F2;
	}
	.class_type{
		height: 200rpx;
		padding: 0 34rpx;
		display: flex;
		overflow-x: auto;
		align-items: center;
		.class_type_item{
			width: 130rpx;
			 flex-shrink: 0;  
			.type-icon-box{
				width: 100%;
				display: flex;
				justify-content: center;
				height: 100rpx; 
				align-items: center;
			}
			.text{
				width: 100%;
				font-size: 26rpx; 
				text-align: center;
				font-weight: 400;
				color: #4D4D4D;
			}
			.type-icon{
				width: 56rpx;
				height: 56rpx;
			}
		}
	}
	.sper-box{
		padding: 0 5rpx;
	}
.home_head{
	background: #fff;
	width: 100%;
	height: 88rpx;
	display: flex;
	margin-top: 110rpx;
	padding: 0 36rpx;
	box-sizing: border-box;
	justify-content: space-between;
	.icon {
				width: 36rpx;
				height: 36rpx;
			}
			.score{
				display: flex;
				align-items: center;
			}
	.home_head_left{
		display: flex;
		align-items: center;
		.text{
			padding: 0 12rpx;
		}
		.total{
			background: #E85034;
			border-radius: 4rpx;
			color: #fff;
			padding: 0 6rpx;
		}
		 
	}
	.home_head_right{
		display: flex;
		align-items: center;
		.rule-float-btn{
			margin-left: 46rpx;
		}
	}
}
</style>
